﻿using System;

namespace ConsoleApplication1.RuntimeAutofac
{
    public enum RoleName
    {
        Premium,
        Normal
    }

    public interface IDataService
    {
        string GetData();
    }

    public class PremiumDataService : IDataService
    {
        public string GetData()
        {
            return this.GetType().Name;
        }
    }

    public class NormalDataService : IDataService
    {
        public string GetData()
        {
            return this.GetType().Name;
        }
    }

    public interface IHomeControler
    {
        void GetData(RoleName roleName);
    }

    public class HomeControler : IHomeControler
    {
        private readonly Func<RoleName, IDataService> _dataServiceFactory;

        public HomeControler(Func<RoleName, IDataService> dataServiceFactory)
        {
            _dataServiceFactory = dataServiceFactory;
        }

        public void GetData(RoleName roleName)
        {
            var dataService = _dataServiceFactory(roleName);
            var data = dataService.GetData();
            Console.WriteLine(data);
        }
    }
}
